/**
 * 
 */
package com.ffcs.crmd.tsp.server.jdbc;

/**
 * 功能说明:
 *
 * @author FFCS-ZHONGFUHUA
 * 
 * @since 
 *
 */
public interface SqlConstants extends ColConstants {
    
    // TSP_JOB_GROUP
    final String GET_JOB_GROUP            = "SELECT * FROM " + TABLE_JOB_GROUP + " WHERE " + COL_ID + " = ? OR (" + COL_CLUSTER_NAME
        + " = ? AND " + COL_NAME + " = ?)";
    
    final String SELECT_JOB_GROUP         = "SELECT DISTINCT TJG.* FROM " + TABLE_JOB_GROUP + " TJG LEFT JOIN " + TABLE_TASK_IDENTITY + " TTI ON TJG.ID = TTI.JOB_GROUP_ID WHERE 1 = 1 ";
    
    final String INSERT_JOB_GROUP         = "INSERT INTO " + TABLE_JOB_GROUP + " (" + COL_ID + ", " + COL_NAME + ", " + COL_DESCRIPTION + ", "
        + COL_CLUSTER_NAME + ") VALUES (?, ?, ?, ?)";
    
    final String UPDATE_JOB_GROUP         = "UPDATE " + TABLE_JOB_GROUP + " SET " + COL_CLUSTER_NAME + " = ?, " + COL_NAME + " = ?, "
        + COL_DESCRIPTION + " = ? WHERE " + COL_ID + " = ?";
    
    final String DELETE_JOB_GROUP         = "DELETE FROM " + TABLE_JOB_GROUP + " WHERE " + COL_ID + " = ?";
    
    // TSP_JOB_DETAIL_PARAM
    final String GET_JOB_DETAIL_PARAM     = "SELECT * FROM " + TABLE_JOB_DETAIL_PARAM + " WHERE " + COL_ID + " = ? OR ("
        + COL_JOB_DETAIL_PARAM_JOB_DETAIL_ID + " = ? AND " + COL_JOB_DETAIL_PARAM_MEKY + " = ?)";
    
    final String SELECT_JOB_DETAIL_PARAM  = "SELECT * FROM " + TABLE_JOB_DETAIL_PARAM + " WHERE 1 = 1 ";
    
    final String INSERT_JOB_DETAIL_PARAM  = "INSERT INTO " + TABLE_JOB_DETAIL_PARAM + " (" + COL_ID + ", " + COL_JOB_DETAIL_PARAM_MEKY + ", "
        + COL_JOB_DETAIL_PARAM_MVALUE + ", " + COL_JOB_DETAIL_PARAM_JOB_DETAIL_ID + ", " + COL_CLUSTER_NAME + ") VALUES (?, ?, ?, ?, ?)";
    
    final String UPDATE_JOB_DETAIL_PARAM  = "UPDATE " + TABLE_JOB_DETAIL_PARAM + " SET " + COL_JOB_DETAIL_PARAM_MVALUE + " = ? WHERE " + COL_ID
        + " = ?";
    
    final String DELETE_JOB_DETAIL_PARAM  = "DELETE FROM " + TABLE_JOB_DETAIL_PARAM + " WHERE 1 = 1";
    
    // TSP_JOB_DETAIL
    final String GET_JOB_DETAIL           = "SELECT TJD.*, TJ.NAME AS JOB_NAME FROM " + TABLE_JOB_DETAIL + " TJD LEFT JOIN " + TABLE_JOB
        + " TJ ON TJD." + COL_JOB_DETAIL_JOB_ID + " = TJ." + COL_ID + " WHERE TJD." + COL_ID + " = ? OR (TJD." + COL_CLUSTER_NAME
        + " = ? AND TJD." + COL_NAME + " = ?)";
    
    final String SELECT_JOB_DETAIL        = "SELECT TJD.*, TJ.NAME AS JOB_NAME FROM " + TABLE_JOB_DETAIL + " TJD LEFT JOIN " + TABLE_JOB
        + " TJ ON TJD." + COL_JOB_DETAIL_JOB_ID + " = TJ." + COL_ID + " WHERE 1 = 1 ";
    
    final String INSERT_JOB_DETAIL        = "INSERT INTO " + TABLE_JOB_DETAIL + " (" + COL_ID + ", " + COL_NAME + ", " + COL_DESCRIPTION + ", "
        + COL_JOB_DETAIL_START_TIME + ", " + COL_JOB_DETAIL_END_TIME + ", " + COL_JOB_DETAIL_JOB_ID + ", " + COL_JOB_DETAIL_RUNNING + ", "
        + COL_CLUSTER_NAME + ") " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
    
    final String UPDATE_JOB_DETAIL        = "UPDATE " + TABLE_JOB_DETAIL + " SET " + COL_DESCRIPTION + " = ?, " + COL_JOB_DETAIL_START_TIME
        + " = ?, " + COL_JOB_DETAIL_END_TIME + " = ?, " + COL_JOB_DETAIL_RUNNING + " = ? WHERE " + COL_ID + " = ?";
    
    final String DELETE_JOB_DETAIL        = "DELETE FROM " + TABLE_JOB_DETAIL + " WHERE 1 = 1";
    
    final String PAUSE_JOB_DETAIL         = "UPDATE " + TABLE_JOB_DETAIL + " SET " + COL_JOB_DETAIL_RUNNING + " = 0 WHERE 1 = 1";
    
    final String RESUME_JOB_DETAIL        = "UPDATE " + TABLE_JOB_DETAIL + " SET " + COL_JOB_DETAIL_RUNNING + " = 1 WHERE 1 = 1";
    
    // TSP_TASK_IDENTITY
    final String GET_TASK_IDENTITY        = "SELECT * FROM " + TABLE_TASK_IDENTITY + " WHERE (" + COL_CLUSTER_NAME + " = ? AND "
        + COL_TASK_IDENTITY_IDENTITY + " = ?) OR " + COL_ID + " = ?";
    
    final String SELECT_TASK_IDENTITY     = "SELECT * FROM " + TABLE_TASK_IDENTITY + " WHERE 1 = 1 ";
    
    final String INSERT_TASK_IDENTITY     = "INSERT INTO " + TABLE_TASK_IDENTITY + " (" + COL_ID + ", " + COL_TASK_IDENTITY_IDENTITY + ", "
        + COL_NAME + ", " + COL_DESCRIPTION + ", " + COL_TASK_IDENTITY_THREAD_NUM + ", " + COL_TASK_IDENTITY_THREAD_PRIORITY_WEIGHT + ", "
        + COL_TASK_IDENTITY_BATCH_THREAD_NUM + ", " + COL_TASK_IDENTITY_BATCH_THREAD_PRIORITY_WEIGHT + ", " + COL_TASK_IDENTITY_JOB_GROUP_ID
        + ", " + COL_CLUSTER_NAME + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    
    final String DELETE_TASK_IDENTITY     = "DELETE FROM " + TABLE_TASK_IDENTITY + " WHERE 1 = 1";
    
    final String UPDATE_TASK_IDENTITY     = "UPDATE " + TABLE_TASK_IDENTITY + " SET " + COL_TASK_IDENTITY_IDENTITY + " = ?, " + COL_NAME
        + " = ?, " + COL_DESCRIPTION + " = ?, " + COL_TASK_IDENTITY_THREAD_NUM + " = ?, " + COL_TASK_IDENTITY_THREAD_PRIORITY_WEIGHT + " = ?, "
        + COL_TASK_IDENTITY_BATCH_THREAD_NUM + " = ?, " + COL_TASK_IDENTITY_BATCH_THREAD_PRIORITY_WEIGHT + " = ?, "
        + COL_TASK_IDENTITY_JOB_GROUP_ID + " = ? WHERE " + COL_ID + " = ?";
    
    // TSP_JOB_IDENTITY_INFO
    final String GET_JOB_IDENTITY_INFO    = "SELECT * FROM " + TABLE_JOB_IDENTITY_INFO + " WHERE (" + COL_JOB_IDENTITY_INFO_TASK_IDENTITY_ID
        + " = ? AND " + COL_JOB_IDENTITY_INFO_JOB_ID + " = ? ) OR " + COL_ID + " = ?";
    
    final String SELECT_JOB_IDENTITY_INFO = "SELECT * FROM " + TABLE_JOB_IDENTITY_INFO + " WHERE 1 = 1 ";
    
    final String INSERT_JOB_IDENTITY_INFO = "INSERT INTO " + TABLE_JOB_IDENTITY_INFO + " (" + COL_ID + ", " + COL_JOB_IDENTITY_INFO_JOB_ID + ", "
        + COL_JOB_IDENTITY_INFO_TASK_IDENTITY_ID + ", " + COL_CLUSTER_NAME + ", " + COL_JOB_IDENTITY_INFO_IDENTITY + ", " + COL_JOB_IDENTITY_INFO_DESCRIPTION + ") VALUES (?, ?, ?, ?, ?, ?)";
    
    final String DELETE_JOB_IDENTITY_INFO = "DELETE FROM " + TABLE_JOB_IDENTITY_INFO + " WHERE 1 = 1";
    
    final String UPDATE_JOB_IDENTITY_INFO = "UPDATE " + TABLE_JOB_IDENTITY_INFO + " SET " + COL_JOB_IDENTITY_INFO_IDENTITY + " = ? WHERE " + COL_ID + "= ?";
    
    // TSP_JOB
    final String GET_JOB                  = "SELECT * FROM " + TABLE_JOB + " WHERE (" + COL_CLUSTER_NAME + " = ? AND " + COL_NAME + " = ?) OR "
        + COL_ID + " = ? ";
    
    final String SELECT_JOB               = "SELECT DISTINCT TJ.*, TJG.`NAME` AS JOB_GROUP_NAME FROM " + TABLE_JOB + " TJ LEFT JOIN " + TABLE_JOB_GROUP
        + " TJG ON TJ." + COL_JOB_JOB_GROUP_ID + " = TJG." + COL_ID + " LEFT JOIN " + TABLE_JOB_IDENTITY_INFO + " TJII ON TJ." + COL_ID
        + " = TJII." + COL_JOB_IDENTITY_INFO_JOB_ID + " WHERE 1 = 1 ";
    
    final String INSERT_JOB               = "INSERT INTO " + TABLE_JOB + " (" + COL_ID + ", " + COL_NAME + ", " + COL_JOB_JOB_CLASS + ", "
        + COL_JOB_CRON_EXPRESSION + ", " + COL_JOB_REPEAT_COUNT + ", " + COL_JOB_REPEAT_INTERVAL + "," + COL_JOB_EXECUTE_TIMEOUT + ", "
        + COL_JOB_BUFFER_SIZE_LIMIT + ", " + COL_JOB_JOB_TYPE + ", " + COL_JOB_REPEAT_TYPE + ", " + COL_JOB_MISFIRE_INSTRUCTION + ", "
        + COL_JOB_SHOULD_RECOVER + ", " + COL_JOB_JOB_GROUP_ID + ", " + COL_JOB_RESET_DEATH_DELAY_TIME + ", " + COL_JOB_TIMEOUT_POLICY + ", "
        + COL_JOB_PRIORITY + ", " + COL_CLUSTER_NAME + ", " + COL_DESCRIPTION + ") VALUES "
        + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    
    final String UPDATE_JOB               = "UPDATE " + TABLE_JOB + " SET " + COL_JOB_JOB_CLASS + " = ?, " + COL_JOB_CRON_EXPRESSION + " = ?, "
        + COL_JOB_REPEAT_COUNT + " = ?, " + COL_JOB_REPEAT_INTERVAL + " = ?, " + COL_JOB_EXECUTE_TIMEOUT + " = ?, " + COL_JOB_BUFFER_SIZE_LIMIT
        + " = ?, " + COL_JOB_JOB_TYPE + " = ?, " + COL_JOB_REPEAT_TYPE + " = ?, " + COL_JOB_MISFIRE_INSTRUCTION + " = ?, " + COL_JOB_JOB_GROUP_ID
        + " = ?, " + COL_JOB_RESET_DEATH_DELAY_TIME + " = ?, " + COL_JOB_TIMEOUT_POLICY + " = ?,  " + COL_JOB_PRIORITY + " = ?, "
        + COL_DESCRIPTION + " = ? WHERE " + COL_ID + " = ?";
    
    final String DELETE_JOB               = "DELETE FROM " + TABLE_JOB + " WHERE 1 = 1";
    
    // TSP_SLICE
    
    final String GET_SLICE                = "SELECT * FROM " + TABLE_SLICE + " WHERE (" + COL_SLICE_SKEY + " = ? AND " + COL_SLICE_SLICE_GROUP_ID
        + " = ?) OR " + COL_ID + " = ?";
    
    final String SELECT_SLICE             = "SELECT * FROM " + TABLE_SLICE + " WHERE 1 = 1 ";
    
    final String INSERT_SLICE             = "INSERT INTO " + TABLE_SLICE + " (" + COL_ID + ", " + COL_SLICE_SKEY + ", "
        + COL_SLICE_SLICE_GROUP_ID + ", " + COL_CLUSTER_NAME + ") VALUES (?, ?, ?, ?)";
    
    final String DELETE_SLICE             = "DELETE FROM " + TABLE_SLICE + " WHERE 1 = 1";
    
    final String UPDATE_SLICE             = "UPDATE " + TABLE_SLICE + " SET " + COL_SLICE_SKEY + " = ? WHERE " + COL_ID + " = ?";
    
    // TSP_SLICE_GROUP
    
    final String GET_SLICE_GROUP          = "SELECT * FROM " + TABLE_SLICE_GROUP + " WHERE (" + COL_NAME + " = ? AND " + COL_SLICE_GROUP_JOB_ID
        + " = ?) OR " + COL_ID + " = ?";
    
    final String SELECT_SLICE_GROUP       = "SELECT TSG.*, TJ.NAME AS JOB_NAME FROM " + TABLE_SLICE_GROUP + " TSG LEFT JOIN " + TABLE_JOB
        + " TJ ON TSG." + COL_SLICE_GROUP_JOB_ID + " = TJ." + COL_ID + " WHERE 1 = 1";
    
    final String INSERT_SLICE_GROUP       = "INSERT INTO " + TABLE_SLICE_GROUP + " (" + COL_ID + ", " + COL_NAME + ", " + COL_SLICE_GROUP_JOB_ID
        + ", " + COL_CLUSTER_NAME + ") VALUES (?, ?, ?, ?)";
    
    final String DELETE_SLICE_GROUP       = "DELETE FROM " + TABLE_SLICE_GROUP + " WHERE 1 = 1";
    
    final String UPDATE_SLICE_GROUP       = "UPDATE " + TABLE_SLICE_GROUP + " SET " + COL_NAME + " = ?, " + COL_SLICE_GROUP_JOB_ID
        + " = ? WHERE " + COL_ID + " = ?";
}
